home *** CD-ROM | disk | FTP | other *** search
-
-
-
- List C Library Procedures List
-
-
-
- _________________________________________________________________
-
- NNAAMMEE
- List - overview of circular linked list routines.
-
- SSYYNNOOPPSSIISS
- ##iinncclluuddee <<lliisstt..hh>>
-
- LLiisstt__IInniitt(_h_e_a_d_e_r_P_t_r)
- LLiisstt__IInniittEElleemmeenntt(_i_t_e_m_P_t_r)
- LLiisstt__IInnsseerrtt(_i_t_e_m_P_t_r, _d_e_s_t_P_t_r)
- LLiisstt__LLiissttIInnsseerrtt(_h_e_a_d_e_r_P_t_r, _d_e_s_t_P_t_r)
- LLiisstt__RReemmoovvee(_i_t_e_m_P_t_r)
- LLiisstt__MMoovvee(_i_t_e_m_P_t_r, _d_e_s_t_P_t_r)
-
- LLIISSTT__AAFFTTEERR(_i_t_e_m_P_t_r)
- LLIISSTT__BBEEFFOORREE(_i_t_e_m_P_t_r)
- LLIISSTT__AATTFFRROONNTT(_h_e_a_d_e_r_P_t_r)
- LLIISSTT__AATTRREEAARR(_h_e_a_d_e_r_P_t_r)
-
- LLIISSTT__FFOORRAALLLL(_h_e_a_d_e_r_P_t_r, _i_t_e_m_P_t_r)
-
- LLiisstt__IIssEEmmppttyy((_h_e_a_d_e_r_P_t_r))
- LLiisstt__IIssAAttEEnndd(_h_e_a_d_e_r_P_t_r, _i_t_e_m_P_t_r)
- LLiisstt__FFiirrsstt((_h_e_a_d_e_r_P_t_r))
- LLiisstt__LLaasstt((_h_e_a_d_e_r_P_t_r))
- LLiisstt__PPrreevv((_i_t_e_m_P_t_r))
- LLiisstt__NNeexxtt((_i_t_e_m_P_t_r))
-
- AARRGGUUMMEENNTTSS
- List_Links *_h_e_a_d_e_r_P_t_r (in) Pointer to the header of
- a list.
-
- List_Links *_i_t_e_m_P_t_r (in) Pointer to a member of a
- list (possibly the
- header).
-
- List_Links *_d_e_s_t_P_t_r (in) Pointer to the member
- after which to insert or
- move another member.
-
- _________________________________________________________________
-
-
- IINNTTRROODDUUCCTTIIOONN
- The LLiisstt__ routines define the ``list'' abstraction, which
- enables one to link together arbitrary data structures.
- Lists are doubly-linked and circular. A list contains a
- header followed by its real members, if any. (An empty list
- therefore consists of a single element, the header, whose
- _n_e_x_t_P_t_r and _p_r_e_v_P_t_r fields point to itself). To refer to a
- list as a whole, the user keeps a pointer to the header;
- that header is initialized by a call to LLiisstt__IInniitt(()), which
- creates an empty list given a pointer to a List_Links
-
-
-
- Sprite v.1.0 Printed: December 14, 1989 1
-
-
-
-
-
-
- List C Library Procedures List
-
-
-
- structure (described below).
-
- The links are contained in a two-element structure called
- List_Links. A list joins List_Links records (that is, each
- List_Links structure points to other List_Links structures),
- but if the List_Links is the first field within a larger
- structure, then the larger structures are effectively linked
- together as shown in Figure 1.
-
- A typical structure might be something like:
-
- typedef struct {
- List_Links links;
- char ch;
- int flags;
- } EditChar;
-
- It is possible to link structures through List_Links fields
- that are not at the beginning of the larger structure, but
- it is then necessary to perform an additional pointer
- indirection to find the beginning of the larger structure,
- given a pointer to some point within it. The easiest way to
- do this is to define a structure that contains a List_Links
- field and a pointer to the larger structure, such as:
- typedef struct {
- List_Links links;
- LargeStruct *structPtr;
- } LargeStructLink;
-
- By including a ``LargeStructLink'' within a ``LargeStruct''
- and setting the structPtr field of the LargeStructLink to
- point to the LargeStruct itself, LargeStruct structures may
- be linked together in a list that is contained in the middle
- of the structure rather than the beginning.
-
-
- UUSSAAGGEE
- After a list has been initialized by calling LLiisstt__IInniitt, ele-
- ments may be inserted, deleted, or moved within the list.
- Before an element is inserted in a list for the first time
- it must be initialized by calling the routine
- LLiisstt__IInniittEElleemmeenntt. To insert a List_Links element into a
- list, LLiisstt__IInnsseerrtt is called with two arguments. The first
- argument is a pointer to the structure to be inserted into a
- list, and the second argument is a pointer to the list
- member after which it is to be inserted. Typically, the
- following macros are used to select the insertion point or
- the destination of a LLiisstt__MMoovvee:
-
-
-
- o+ LLIISSTT__BBEEFFOORREE(_i_t_e_m_P_t_r) Insert the element before
-
-
-
- Sprite v.1.0 Printed: December 14, 1989 2
-
-
-
-
-
-
- List C Library Procedures List
-
-
-
- *_i_t_e_m_P_t_r.
-
- o+ LLIISSTT__AAFFTTEERR(_i_t_e_m_P_t_r) Insert the element after
- *_i_t_e_m_P_t_r.
-
- o+ LLIISSTT__AATTFFRROONNTT(_h_e_a_d_e_r_P_t_r) Insert the element at the
- front of the list.
-
- o+ LLIISSTT__AATTRREEAARR(_h_e_a_d_e_r_P_t_r) Insert the element at the
- end of the list.
-
- To insert a list into another list, call LLiisstt__LLiissttIInnsseerrtt |
- with the header of the list to be inserted and a pointer to |
- the member of the second list after which the first list is |
- to be inserted. After calling LLiisstt__LLiissttIInnsseerrtt, the header |
- of the first list is no longer valid and may be destroyed.
-
- To remove a structure from a list, call LLiisstt__RReemmoovvee with a
- pointer to the structure to be removed. To move a structure,
- call LLiisstt__MMoovvee with two arguments: a pointer to the struc-
- ture to be moved, and a pointer to the structure after which
- it is to be placed. LLiisstt__MMoovvee(_i_t_e_m_P_t_r, _d_e_s_t_P_t_r) is there-
- fore equivalent to LLiisstt__RReemmoovvee(_i_t_e_m_P_t_r) followed by
- LLiisstt__IInnsseerrtt(_i_t_e_m_P_t_r, _d_e_s_t_P_t_r).
-
-
- AADDDDIITTIIOONNAALL UUTTIILLIITTIIEESS
- Several other macros are available for the manipulation of
- List_Links. LLIISSTT__FFOORRAALLLL(_h_e_a_d_e_r_P_t_r, _i_t_e_m_P_t_r) is used to step
- through each element in the list pointed to by headerPtr,
- setting itemPtr to point to each element in turn.
- LLIISSTT__FFOORRAALLLL is used typically by casting _i_t_e_m_P_t_r as a
- pointer to the entire structure, as in:
- List_Links *headerPtr; /* pointer to head of existing list */
- List_Links *itemPtr; /* place-holder during loop */
- EditChar *charPtr; /* pointer to entire EditChar structure */
-
- LIST_FORALL(headerPtr, itemPtr) {
- charPtr = (EditChar *) itemPtr;
- /* operations using charPtr */
- }
-
- The following macros may be useful to those who use
- List_Links at a ``lower'' level than looping through an
- entire list:
-
- o+ LLiisstt__IIssEEmmppttyy(_h_e_a_d_e_r_P_t_r) returns TRUE if _h_e_a_d_e_r_P_t_r
- points to an empty list.
-
- o+ LLiisstt__IIssAAttEEnndd(_h_e_a_d_e_r_P_t_r, _i_t_e_m_P_t_r)
- returns TRUE if _i_t_e_m_P_t_r
- is past the end of the
-
-
-
- Sprite v.1.0 Printed: December 14, 1989 3
-
-
-
-
-
-
- List C Library Procedures List
-
-
-
- list; i.e., it points to
- the header.
-
- o+ LLiisstt__FFiirrsstt(_h_e_a_d_e_r_P_t_r)
-
- o+ LLiisstt__LLaasstt(_h_e_a_d_e_r_P_t_r) LLiisstt__FFiirrsstt returns the
- first member in a list,
- and LLiisstt__LLaasstt returns the
- last member. If the list
- is empty, the header is
- considered to be the
- first and last member.
-
- o+ LLiisstt__PPrreevv(_i_t_e_m_P_t_r) returns a pointer to the
- member preceding the
- given member in its list.
- Note: if the given
- member is the first ele-
- ment of the list,
- LLiisstt__PPrreevv will return the
- list header.
-
- o+ LLiisstt__NNeexxtt(_i_t_e_m_P_t_r) returns the next member
- of the list. Note: if
- the given member is the
- last element of the list,
- LLiisstt__NNeexxtt will return the
- list header.
-
- KKEEYYWWOORRDDSS
- list, linked, circular, List_Links, data structures
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Sprite v.1.0 Printed: December 14, 1989 4
-
-
-
-